﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowSprintDetails.aspx.cs"
    Inherits="Actuals.ShowSprintDetails" MaintainScrollPositionOnPostback="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" id="head1">
    <link href="~/Actuals.css" runat="server" rel="Stylesheet" type="text/css" />
    <link href="~/themes/ui-lightness/jquery.ui.all.css" rel="Stylesheet" runat="server" />
    <title></title>
    <style>
        body
        {
            font: bold 12px arial;
        }
        
        span
        {
            float: left;
            margin-top: 17px;
            text-align: center;
            width: 100%;
        }
        
        #trash, #items, .item
        {
            height: 50px;
            width: 50px;
        }
        
        #trash
        {
            color: #354e62;
        }
        
        #items
        {
            margin-top: 10px;
            width: 100%;
        }
        
        .todoitem
        {
            background: #cdcdcd;
            color: #3b3b3b;
            float: left;
            margin-right: 10px;
            border-color: Gray;
            border: 1px solid;
        }
        
        .inprogitem
        {
            background: yellow;
            color: black;
            float: left;
            margin-right: 10px;
            border-color: Gray;
            border: 1px solid;
        }
        
        .closeditem
        {
            background: green;
            color: white;
            float: left;
            margin-right: 10px;
            border-color: Gray;
            border: 1px solid;
        }
        .over
        {
            background-color: yellow;
        }
        
        .out
        {
            background-color: #a6bcce;
        }
    </style>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.core.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.widget.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.mouse.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.draggable.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.droppable.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.datepicker.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.blockUI.js") %>"></script>
    <script type="text/javascript">

        $(function () {
            $('div[id*=ToDoItem]').draggable({
                containment: "#container",
                revert: false,
                start: function (event, ui) {
                    ui.helper.data('rejected', false);
                    ui.helper.data('type', 'todo');
                    ui.helper.data('original-position', ui.helper.offset());
                },
                stop: function (event, ui) {
                    if (ui.helper.data('rejected') == true) {
                        ui.helper.offset(ui.helper.data('original-position'));
                    }
                }
            }
            );

            $('div[id*=InProgItem]').draggable({
                containment: "#container",
                revert: false,
                start: function (event, ui) {
                    ui.helper.data('rejected', false);
                    ui.helper.data('type', 'inprog');
                    ui.helper.data('original-position', ui.helper.offset());
                },
                stop: function (event, ui) {
                    if (ui.helper.data('rejected') == true) {
                        ui.helper.offset(ui.helper.data('original-position'));
                    }
                }
            }
            );

            $('div[id*=ClosedItem]').draggable({
                containment: "#container",
                revert: false,
                start: function (event, ui) {
                    ui.helper.data('rejected', false);
                    ui.helper.data('type', 'closed');
                    ui.helper.data('original-position', ui.helper.offset());
                },
                stop: function (event, ui) {
                    if (ui.helper.data('rejected') == true) {
                        ui.helper.offset(ui.helper.data('original-position'));
                    }
                }
            }
            );

            $('div[id*=inprog]').droppable({
                tolerance: 'touch',
                //accept: '#todoitem',
                drop: function (event, ui) {

                    if ((ui.helper.data('type') == 'todo') || ((ui.helper.data('type') == 'closed'))) {
                        var answer = confirm('Permantly move this item?');
                        if (answer == false)
                            ui.draggable.data('rejected', true);
                        else {

                            changeStatus(ui.draggable.attr('id'), 'I', '<%=Session["EmployeeId"] %>');
                            ui.draggable.removeClass('todoitem').addClass('inprogitem');
                            ui.helper.data('type', 'inprog');
                            ui.draggable.data('rejected', false);
                        }
                    }
                    else {
                        alert('you cannot do this action');
                        ui.draggable.data('rejected', true);
                    }

                }
            });

            $('div[id*=done]').droppable({
                tolerance: 'touch',
                //accept: '#inprogitem',
                drop: function (event, ui) {
                    //alert(ui.helper.data('type'));
                    if (ui.helper.data('type') == 'inprog') {
                        var answer = confirm('Permantly move this item?');

                        if (answer == false) {
                            ui.draggable.data('rejected', true);
                        }
                        else {
                            // $(this).removeClass('inprogitem').addClass('closeditem');

                            changeStatus(ui.draggable.attr('id'), 'C', '<%=Session["EmployeeId"] %>');
                            ui.draggable.removeClass('inprogitem').addClass('closeditem');
                            ui.helper.data('type', 'done');
                            ui.draggable.data('rejected', false);
                        }
                    }
                    else {
                        alert('you cannot do this action');
                        ui.draggable.data('rejected', true);
                    }
                }
            });



            $('div[id*=todo]').droppable({
                tolerance: 'touch',
                //accept: '#inprogitem',
                drop: function (event, ui) {
                    //alert(ui.helper.data('type'));
                    if (ui.helper.data('type') == 'inprog') {
                        var answer = confirm('Permantly move this item?');

                        if (answer == false) {
                            ui.draggable.data('rejected', true);
                        }
                        else {
                            // $(this).removeClass('inprogitem').addClass('closeditem');
                            var returnVal = changeStatus(ui.draggable.attr('id'), 'T', '<%=Session["EmployeeId"] %>');
                            if ($("#ajaxrep").val() == "f") {
                                ui.draggable.data('rejected', true);
                            }
                            else {
                                ui.draggable.removeClass('inprogitem').addClass('closeditem');
                                ui.helper.data('type', 'done');
                                ui.draggable.data('rejected', false);
                            }
                        }
                    }
                    else {
                        alert('you cannot do this action');
                        ui.draggable.data('rejected', true);
                    }
                }
            });

        });
        //
        function changeStatus(taskId, newStatus, employeeId) {

            var pageUrl = '<%=ResolveUrl("ShowSprintDetails.aspx")%>';
            $.blockUI();
            taskId = taskId.replace("ToDoItem", "");
            taskId = taskId.replace("InProgItem", "");
            taskId = taskId.replace("ClosedItem", "");
            //alert(taskId);
            var ret = true;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: "{taskId:'" + taskId + "',newStatus:'" + newStatus + "',employeeId:'" + employeeId + "'}",
                url: pageUrl + "/UpdateStatus",
                dataType: "json",
                success: function (data) {


                    if (data.d == '-99') {
                        alert('You can move only your items');
                        $("#ajaxrep").val("f");
                    }
                    else
                        alert('updated!');
                    $.unblockUI();

                },
                error: function (request, error) {

                }


            });
            return ret;
        }
    </script>
    <script type="text/javascript">

        function UpdateTechnicalTask(technicalTaskId, userStoryId) {

            var url = 'AddTechnicalTasks.aspx?Mode=Edit&Form=ShowSprintDetails&TechnicalTaskId=' + technicalTaskId + '&UserStoryId=' + userStoryId;

            var result = window.showModalDialog(url, this,
                           'dialogHeight:390px;dialogWidth:430px;Scroll:yes;Help:no;Status:yes;Center:yes;Toolbars:no;');

            //__doPostBack("refresh", "refresh");
        }

        function AddTechnicalTask(userStoryId) {

            var url = 'AddTechnicalTasks.aspx?Mode=Add&UserStoryId=' + userStoryId;

            var result = window.showModalDialog(url, this,
                           'dialogHeight:370px;dialogWidth:430px;Scroll:yes;Help:no;Status:yes;Center:yes;Toolbars:no;');
            __doPostBack("refresh", "refresh");
        }

        function ShowAddUserStory() {
            var sprintId = document.getElementById("ddlSprint").value;
            var projectId = document.getElementById("ddlProject").value;
            var releaseId = document.getElementById("ddlRelease").value;
            var url = 'AddUserStory.aspx?Mode=AddForSprint&SprintId=' + sprintId + '&ProjectId=' + projectId + '&ReleaseId=' + releaseId;
            var result = window.showModalDialog(url, this,
                'dialogHeight:330px;dialogWidth:255px;Status:yes;Toolbars:no;Scroll:yes;Help:no;Center:yes;');
            __doPostBack('refresh', 'refresh');
        }
        function CloseSprintPopUp() {
            var sprintId = document.getElementById("ddlSprint").value;
            var url = 'CloseSprint.aspx?Mode=Close&SprintId=' + sprintId;
            var result = window.showModalDialog(url, this, 'dialogHeight:200px;dialogWidth:200px;Status;yes;Toolbars:no;Scroll:yes;Center:yes;');
            __doPostBack('refresh', 'refresh');
        }
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divShowSprintDetails" runat="server">
        <center>
            <asp:Label ID="lblMsg" runat="server" CssClass="label"></asp:Label>
            <table width="100%">
                <tr>
                    <td width="5%">
                        <asp:Label ID="lblProject" runat="server" CssClass="label">Project</asp:Label>
                    </td>
                    <td width="10%">
                        <asp:DropDownList ID="ddlProject" runat="server" CssClass="textfield" AutoPostBack="true"
                            OnSelectedIndexChanged="ddlProject_OnSelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td width="5%">
                        <asp:Label ID="lblRelease" runat="server" CssClass="label">Release</asp:Label>
                    </td>
                    <td align="left" width="10%">
                        <asp:DropDownList ID="ddlRelease" runat="server" CssClass="textfield" AutoPostBack="true"
                            OnSelectedIndexChanged="ddlRelease_OnSelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                    <td width="5%">
                        <asp:Label ID="lblSprint" runat="server" CssClass="label">Sprint</asp:Label>
                    </td>
                    <td align="left" width="10%">
                        <asp:DropDownList ID="ddlSprint" runat="server" CssClass="textfield">
                        </asp:DropDownList>
                    </td>
                    <td width="55%">
                        <asp:Button ID="btnGetSprintDetails" runat="server" Text="Get" OnClick="btn_GetSprintDetails_click" />
                        <asp:Button ID="btnCloseSprint" runat="server" CssClass="button" Text="CloseSprint"
                            OnClientClick="CloseSprintPopUp();" />
                        <asp:Button ID="btnAddUserStory" runat="server" Text="Add UserStory" OnClientClick="ShowAddUserStory();" />
                        <asp:HiddenField ID="ajaxresp" runat="server" />
                    </td>
                </tr>
            </table>
        </center>
    </div>
    <!--new drag & droppable content-->
    <!-- end-->
    <div id="div2" style="border: solid 1px silver; height: 600px; overflow-x: hidden;
        overflow-y: auto; width: 100%;">
        <table width="100%" border="1" class="sprintUserStory">
            <%--  <tr>
                <td width="1%">
                    
                </td>
                <td width="13%">
                    <asp:Label ID="lblHd1" class="label" runat="server" Text="User Story"></asp:Label>
                </td>
                <td width="6%">
                    <asp:Label ID="Label1" class="label" runat="server" Text="Story Points"></asp:Label>
                </td>
                <td width="6%">
                    <asp:Label ID="Label2" class="label" runat="server" Text="Status"></asp:Label>
                </td>
                  <td width="6%">
                    <asp:Label ID="Label3" class="label" runat="server" Text="Owner"></asp:Label>
                </td>
                   <td width="6%">
                    <asp:Label ID="Label4" class="label" runat="server" Text="Code Review Status"></asp:Label>
                </td>
                     <td width="6%">
                    <asp:Label ID="Label5" class="label" runat="server" Text="Code Review Done By"></asp:Label>
                </td>
            </tr>--%>
        </table>
        <asp:Repeater runat="server" ID="repeaterShowUserStoryDetails" OnItemCommand="repeaterShowUserStoryDetails_OnItemCommand">
            <ItemTemplate>
                <table width="100%" border="1" class="sprintUserStory">
                    <tr>
                        <td width="1%">
                            <asp:Label ID="lblUserStoryId" class="label" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "UserStoryId")%>'
                                Visible="false"></asp:Label>
                        </td>
                        <td width="30%">
                            <asp:Label ID="lblUserStoryDescription" class="label" runat="server" Text='<%#getUserStoryAndTaskShortName(Eval("TaskId"),Eval("UserStoryId"))%>' />
                        </td>
                        <td width="6%">
                            <asp:Label ID="lblStorypoints" class="label" runat="server" Text='<%#Bind("StoryPoints")%>' />
                        </td>
                        <td width="58%">
                            <asp:Button ID="btnAddTechnicalTask" runat="server" Text="AddTechTask" CommandName="AddTechnicalTask"
                                UseSubmitBehavior="False" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"UserStoryId")%>' />
                        </td>
                    </tr>
                </table>
                <table border="1" width="100%">
                    <tr>
                        <td height="100%" width="30%">
                            <div id="todo" runat="server" style="height: 100%; width: 100%">
                                <asp:Repeater runat="server" ID="repeater1" OnItemCommand="repeaterShowTechnicalTaskDetails_OnItemCommand"
                                    DataSource='<%# DataBinder.Eval(Container.DataItem, "TechnicalTasksToDo") %>'>
                                    <ItemTemplate>
                                        <div class="todoitem" style="width: 120px" id='ToDoItem<%# DataBinder.Eval(Container.DataItem, "TechnicalTaskId")%>'>
                                            <table border="1">
                                                <tr>
                                                    <td>
                                                        <div style="width: 90px; word-wrap: break-word;">
                                                            <%# DataBinder.Eval(Container.DataItem, "UserStoryDescription")%>
                                                        </div>
                                                    </td>
                                                    <td valign=top>
                                                        <asp:ImageButton ID="ImageButton1" Width="15px" Height="15px" runat="server" ImageUrl="~/Edit.bmp"
                                                            OnClientClick='<%#"UpdateTechnicalTask("+ Eval("TechnicalTaskId") + "," + Eval("UserStoryId") + ");"%>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        Est:
                                                        <%# Eval("EstimatedTime")%>
                                                        Rem:
                                                        <%# Eval("RemainingTime")%>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </div>
                        </td>
                        <td height="100%" width="30%">
                            <div id="inprog" runat="server" style="height: 100%; width: 100%;">
                                <asp:Repeater runat="server" ID="repeater2" OnItemCommand="repeaterShowTechnicalTaskDetails_OnItemCommand"
                                    DataSource='<%# DataBinder.Eval(Container.DataItem, "TechnicalTasksInProg") %>'>
                                    <ItemTemplate>
                                        <div class="inprogitem" style="width: 120px" id='InProgItem<%# DataBinder.Eval(Container.DataItem, "TechnicalTaskId")%>'>
                                            <table border="1">
                                                <tr>
                                                    <td>
                                                        <div style="width: 90px; word-wrap: break-word;">
                                                            <%# DataBinder.Eval(Container.DataItem, "UserStoryDescription")%>
                                                        </div>
                                                    </td>
                                                    <td valign=top>
                                                        <asp:ImageButton ID="ImageButton1" Width="15px" Height="15px" runat="server" ImageUrl="~/Edit.bmp"
                                                            OnClientClick='<%#"UpdateTechnicalTask("+ Eval("TechnicalTaskId") + "," + Eval("UserStoryId") + ");"%>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        Est:
                                                        <%# Eval("EstimatedTime")%>
                                                        Rem:
                                                        <%# Eval("RemainingTime")%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <%# getEmpName(Eval("TaskCompletedBy"))%>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </div>
                        </td>
                        <td height="100%" width="30%">
                            <div id="done" runat="server" style="height: 100%; width: 100%;">
                                <asp:Repeater runat="server" ID="repeater3" OnItemCommand="repeaterShowTechnicalTaskDetails_OnItemCommand"
                                    DataSource='<%# DataBinder.Eval(Container.DataItem, "TechnicalTasksDone") %>'>
                                    <ItemTemplate>
                                        <div class="closeditem" style="width: 120px" id='ClosedItem<%# DataBinder.Eval(Container.DataItem, "TechnicalTaskId")%>'>
                                            <table border="1">
                                                <tr>
                                                    <td>
                                                        <div style="width: 90px; word-wrap: break-word;">
                                                            <%# DataBinder.Eval(Container.DataItem, "UserStoryDescription")%>
                                                        </div>
                                                    </td>
                                                    <td valign=top>
                                                        <asp:ImageButton ID="ImageButton1" Width="15px" Height="15px" runat="server" ImageUrl="~/Edit.bmp"
                                                            OnClientClick='<%#"UpdateTechnicalTask("+ Eval("TechnicalTaskId") + "," + Eval("UserStoryId") + ");"%>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        Est:
                                                        <%# Eval("EstimatedTime")%>
                                                        Rem:
                                                        <%# Eval("RemainingTime")%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        TakenBy:
                                                        <%# getEmpName(Eval("TaskCompletedBy"))%>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </div>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>
</html>
